import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from '../views/Home.vue'
// import Login from '../views/Login.vue'

Vue.use(VueRouter)

const routes = [
  // {
  //   path: '/',
  //   name: 'login',
  //   component: Login
  // },
  {
    path: '/about',
    name: 'About',
    component: () => import('../views/About.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/Login.vue'),
  //   children:[
  //     {
  //       path: 'regist',
  //       name: 'regist',
  //       component: () => import('../views/Regist.vue'),
  //     }
  // ]
  },
  {
    path:'/regist',
    name: 'regist',
    component: () => import('../views/Regist.vue'),
  },
  {
    path:'/management',
    name: 'management',
    component: () => import('../views/management.vue'),
    beforeEnter:(to,from,next)=>{
      console.log(to);
      console.log(from);
      // var xx=JSON.parse(localStorage.getItem('temp'))||{}
      if(JSON.parse(localStorage.getItem('temp'))==null){
        next('/login')
        // console.log(xx._id);
      }else{
        // console.log(xx._id);
        next();
      }
    }
  },
  {
    path: '/user',
    name: 'user',
    component: () => import('../views/User.vue'),
    beforeEnter:(to,from,next)=>{
      console.log(to);
      console.log(from);
      // var xx=JSON.parse(localStorage.getItem('temp'))||{}
      if(JSON.parse(localStorage.getItem('temp'))==null){
        next('/login')
        // console.log(xx._id);
      }else{
        // console.log(xx._id);
        next();
      }
    },
    children:[
      {
        path:'/',
        redirect:'userhome',
        component: () => import('../views/Userhome.vue')
      },
      {
      path:'userhome',
      name:'userhome',
      component: () => import('../views/Userhome.vue'),
      children:[
        {
          path:'/',
          redirect:'userinfo',
          component: () => import('../views/Userinfo.vue')
        },
        {
          path:'userinfo',
          name:'userinfo',
          component: () => import('../views/Userinfo.vue'),
        },
        {
          path:'history',
          name:'history',
          component: () => import('../views/History.vue'),
        },
      ]
      },
      {
      path:'userstore',
      name:'userstore',
      component: () => import('../views/Userstore.vue'),
      },
      
    ]
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 导航守卫


export default router
